<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>Storeroommanage</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<script type="text/javascript" src="scripts/jquery/jquery-1.7.1.js"></script>
	<link href="style/authority/basic_layout.css" rel="stylesheet" type="text/css">
	<link href="style/authority/common_style.css" rel="stylesheet" type="text/css">
	<script type="text/javascript" src="scripts/authority/commonAll.js"></script>
	<script type="text/javascript" src="scripts/fancybox/jquery.fancybox-1.3.4.js"></script>
	<script type="text/javascript" src="scripts/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
	<link rel="stylesheet" type="text/css" href="style/authority/jquery.fancybox-1.3.4.css" media="screen"></link>
	<script type="text/javascript" src="scripts/artDialog/artDialog.js?skin=default"></script>
	<script type="text/javascript" src="scripts/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript" src="scripts/Myscripts/alpha_add.js"></script>
	
	<script type="text/javascript">
		var req = false;
		var table_innerhtml="";
		function createHTTP(){
		//alert("!");
			if (window.XMLHttpRequest) {
             req = new XMLHttpRequest();
         	}
         	else if (window.ActiveXObject) {
             req = new ActiveXObject("Microsoft.XMLHTTP");
         	}
         	if(!req)
         	alert("no req!");
		}
		function getrefresh(){
			createHTTP();
			//alert("!");
			var product_id = document.getElementById("product_id_id").value;
			var product_name = document.getElementById("product_name_id").value;
			if(product_id==null)
				product_id="";
			if(product_name==null)
				product_name="";
			req.open("post","servlet/Storeroommanageservlet",true);
         	req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
         	req.onreadystatechange=updatePage;
  			req.send("product_id="+encodeURI(encodeURI(product_id))+"&product_name="+encodeURI(encodeURI(product_name))+"&action=refresh");	
		}
		function getmod(){
			var i = arguments[0];
			//alert(i);
			var producti_id = document.getElementById("product"+i+"_id").value;
			var producti_warning_number = document.getElementById("product"+i+"_warning_number").value;
			var producti_max_number = document.getElementById("product"+i+"_max_number").value;
			if(producti_warning_number==null||producti_warning_number=="")
				producti_warning_number="0";
			if(producti_max_number==null||producti_max_number=="")
				producti_max_number="0";
			var re =new RegExp("[1-9][0-9]*");
			if(!re.test(producti_warning_number)||!re.test(producti_max_number)){
				alert("请输入数字");
				getrefresh();
			}
			else if(parseInt(producti_warning_number)>parseInt(producti_max_number))
			{
				alert("警戒值不能超过最大值");
				getrefresh();
			}
			else{
			req.open("post","servlet/Storeroommanageservlet",true);
         	req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
         	req.onreadystatechange=refreshPage;
  			req.send("product_id="+producti_id+"&warning_number="+producti_warning_number+"&max_number="+producti_max_number+"&action=mod");
  			}
		}
		function updatePage(){
			//alert("up");
			//alert(req.readyState);
			if(req.readyState==4)
			{
				//alert(req.status);
				if(req.status=200)
				{
					var xmlDoc = req.responseXML.documentElement;
  					var xproducts = xmlDoc.getElementsByTagName("product");
  					var products_table = document.getElementById("product_info_table");
  					var temp_table_innerHTML = table_innerhtml;
  					for(var i = 0;i<xproducts.length;++i)
  					{
  						//alert(i);
  						var t_product_id = xproducts[i].childNodes[0].firstChild.nodeValue;
  						var t_product_name = xproducts[i].childNodes[1].firstChild.nodeValue;
  						var t_warning_number = xproducts[i].childNodes[2].firstChild.nodeValue;
  						var t_max_number = xproducts[i].childNodes[3].firstChild.nodeValue;
  						temp_table_innerHTML += "<tr><td><input class=\"ui_input_txt02\" type=\"text\" value = \""+t_product_id+"\" id= \"product"+i+"_id\" readonly/></td><td><input class=\"ui_input_txt02\" type=\"text\" value = \""+t_product_name+"\" readonly/></td><td><input class=\"ui_input_txt02\" type=\"text\" value = \""+t_warning_number+"\" id= \"product"+i+"_warning_number\"/></td><td><input class=\"ui_input_txt02\" type=\"text\" value = \""+t_max_number+"\" id= \"product"+i+"_max_number\"/></td><td><input type=\"button\" value = \"重置\" onclick = \"getrefresh()\" class=\"ui_input_btn01\"/> <input type=\"button\" value = \"修改\" onclick = \"getmod("+i+")\" class=\"ui_input_btn01\"/></td></tr>"; 
  					}
  					products_table.innerHTML = temp_table_innerHTML;
  					//alert(products_table.innerHTML);
				}
			}
		}
		function refreshPage(){
		
			if(req.readyState==4)
				{
					//alert(req.status);
					if(req.status=200)
					{
						alert("已更新！");
						getrefresh();
					}
				}
		}
	</script>
  </head>
  
  <body>
  <div id = "add_alpha_id">
    <div id="container">
   	 <div class = "ui_content">
   	  <div class = "box_border">
   	   <div id = "box_top">搜索</div>
    	<table class ="table" width = "100%">
    		<tr><td>商品ID：</td><td><input type="text" id = "product_id_id" onblur="getrefresh()" class="ui_input_txt02"></td></tr>
    		<tr><td>商品名：</td><td><input type="text" id = "product_name_id" onblur="getrefresh()" class="ui_input_txt02"></td></tr>
    	</table>
    	<div id = "box_bottom"> <input type="button" value = "确定" class="ui_input_btn01" onclick="getrefresh();alert('已刷新！')"></div>
    	</div>
    	</div>
    	<div class = "ui_content">
    	 <div class = "box_border">
    	<table id = "product_info_table" width="100%" class="table">
    		<tr><th align="center">商品ID</th><th align="center">商品名</th><th align="center">预警值</th><th align="center">最大值</th><th align="center">操作</th></tr>
    	</table>
    	</div>
    	</div>
    </div>
    </div>
    <script type="text/javascript">
    	table_innerhtml=document.getElementById("product_info_table").innerHTML;
    	//alert(table_innerhtml);
    	getrefresh();
    	//alert("!!!!");
    </script>
    <script type="text/javascript">
   var eitem = document.getElementById("add_alpha_id");
   window.onload = add_alpha(eitem);
   </script>
  </body>
</html>
